-- spell_get_cure
-- created by panyl
-- 每施放一个魔法，属性恢复N

-- 触发器
local triggerHandle = function(who, prop, arg)
    local attrib = prop[2];
    local count = prop[3];
    local isPlayEffect = true;

    -- 巫毒技能根据魔力计算回复量，特殊处理下
    if attrib == "magic_to_hp" then
        if who.type ~= OBJECT_TYPE_USER then
            return;
        end
        attrib = "hp";
        count = math.modf(who:queryAttrib("magic") * count / 1000) + 5;
        count = math.max(1,count);
    end
    if attrib == "hp" then
        if ME.user:queryAttrib("max_hp") <= ME.user:queryAttrib("hp") then
            -- 当前血量已经达到上限了，提升一点，且不飘字
            count = 1;
            isPlayEffect = false;
        else
            -- 不能超出上限
            count = math.min(count, ME.user:queryAttrib("max_hp") - ME.user:queryAttrib("hp"));
        end
    end

    BonusM.doBonus({ 2, attrib, count, }, "prop spell_get_cure");
    if isPlayEffect then
        EventMgr.fire(event.HP_RECOVER, count);
    end

    -- 触发特技发动事件
    EventMgr.fire(event.SPECIAL_SKILL_TRIGGER, { propId = prop[1] });
    return prop[3];
end

return {
    apply = function(prop, baseValue)
        local v = math.modf(baseValue * prop[3] / 1000);
        return baseValue + v;
    end,

    -- 使用魔法卷轴触发
    trigger = triggerHandle,

    record = function(target, prop, path)
        return false;
    end
};